import React, {Component} from "react";
import { Select } from 'antd';
import { connect } from "dva";

@connect(({oil, loading}) => ({
  oilList: oil.oilList
}))
export class OilSelect extends React.Component {

  handleSearch = value => {
    const { dispatch } = this.props
    if (value) {
      dispatch({
        type: 'oil/selectList',
        payload: { oilNo: value }
      })
    } else {
      this.setState({ data: [] });
    }
  };

  render() {
    const{ onSelect } = this.props
    const options = this.props.oilList.map(d => <Option key={d.oilNo}>{d.oilNo}</Option>);
    return (
      <Select
        showSearch
        value = {this.props.value}
        placeholder="请选择油卡"
        defaultActiveFirstOption={false}
        onSelect={onSelect}
        showArrow={false}
        filterOption={false}
        onSearch={this.handleSearch}
        notFoundContent={null}
      >
        {options}
      </Select>
    );
  }
}
